﻿using Resto.CostControl.Core.Facade.SupplierModule.FacadeObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Resto.CostControl.Core.Facade.SupplierModule.DataTransferObject;
using Enterprise.Framework.Core.Container;
using System.Collections.Generic;

namespace Resto.CostControl.UnitTest.SupplierModule
{


    /// <summary>
    ///这是 SupplierContractFOTest 的测试类，旨在
    ///包含所有 SupplierContractFOTest 单元测试
    ///</summary>
    [TestClass()]
    public class SupplierContractFOTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///AddSupplierContract 的测试
        ///</summary>
        [TestMethod()]
        public void AddSupplierContractTest()
        {
            SupplierContractFO target = ObjectCreator.Create<SupplierContractFO>();
            SupplierContractDTO supplierContractDTO = new SupplierContractDTO()
            {
                Code = "a2",
                BeginDate = DateTime.Now.AddYears(-1),
                EndDate = DateTime.Now.AddYears(1),
                SupplierId = "1",
            };

            List<SupplierContractItemDTO> list = new List<SupplierContractItemDTO>();
            SupplierContractItemDTO item1 = new SupplierContractItemDTO()
            {
                MaterialId = "1",
                Price = 100m,
            };
            SupplierContractItemDTO item2 = new SupplierContractItemDTO()
            {
                MaterialId = "2",
                Price = 200m,
            };
            list.Add(item1);
            list.Add(item2);

            supplierContractDTO.Items = list.ToArray();

            target.AddSupplierContract(supplierContractDTO);
            //Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///AddSupplierContract 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateSupplierContractTest()
        {
            SupplierContractFO target = ObjectCreator.Create<SupplierContractFO>();
            SupplierContractDTO supplierContractDTO = new SupplierContractDTO()
            {
                Code = "a3",
                BeginDate = DateTime.Now.AddYears(-1),
                EndDate = DateTime.Now.AddYears(1),
                SupplierId = 2,
            };

            List<SupplierContractItemDTO> list = new List<SupplierContractItemDTO>();
            SupplierContractItemDTO item1 = new SupplierContractItemDTO()
            {
                MaterialId = 1,
                Price = 100m,
            };
            SupplierContractItemDTO item2 = new SupplierContractItemDTO()
            {
                MaterialId = 2,
                Price = 200m,
            };
            list.Add(item1);
            list.Add(item2);

            supplierContractDTO.Items = list.ToArray();

            target.AddSupplierContract(supplierContractDTO);

            List<SupplierContractItemDTO> list2 = new List<SupplierContractItemDTO>();
            SupplierContractItemDTO item21 = new SupplierContractItemDTO()
            {
                MaterialId = 3,
                Price = 300m,
            };
            SupplierContractItemDTO item22 = new SupplierContractItemDTO()
            {
                MaterialId = 4,
                Price = 400m,
            };
            list.Add(item21);
            list.Add(item22);
            supplierContractDTO.Items = list.ToArray();

            target.UpdateSupplierContract(supplierContractDTO);
            //Assert.Inconclusive("无法验证不返回值的方法。");
        }
    }
}
